<?php 
if(!isset($_SESSION)) 
	{ 
		session_start(); 
	}
include '../operations/connection.php';	
if(isset($_REQUEST['namekey']) && isset($_REQUEST['idtemplate']) && isset($_SESSION['lang'])){
		
	function getlang(){
		$lang = $_SESSION['lang'];
		if (empty($lang) || $lang == "EN") {
			$value = "../value/value_en.php";
		} else if($lang == "VN") {
			$value = "../value/value_vn.php";
		}
		else {
			$value = "../value/value_kr.php";
		}
		return $value;
	}
	$value = getlang();
	include($value);
	
	if($_REQUEST['idtemplate']=="ALL"){
		$mkqs=mysql_query("SELECT typedoc.IDTypeDoc,tdn.".$_SESSION['lang']." as tdname,tpn.".$_SESSION['lang']." as tpname from typedoc,staticlang tdn, staticlang tpn,template 
		where typedoc.IDTypeDoc>6 and typedoc.IDTypeDoc!=11 
		and typedoc.IDConfigStaticLang = tdn.IDConfigStaticLang
		and typedoc.IDTemplate = template.IDTemplate and (tdn.EN like '%".$_REQUEST['namekey']."%' or tdn.VN like '%".$_REQUEST['namekey']."%' or tdn.KR like '%".$_REQUEST['namekey']."%' ) 
		and template.IDConfigStaticLang = tpn.IDConfigStaticLang ORDER BY typedoc.IDTypeDoc asc");
	}else{
		$sql="SELECT typedoc.IDTypeDoc,tdn.".$_SESSION['lang']." as tdname,tpn.".$_SESSION['lang']." as tpname 
		from typedoc,staticlang tdn, staticlang tpn,template 
		where typedoc.IDTypeDoc>6 and typedoc.IDTypeDoc!=11 and typedoc.IDConfigStaticLang = tdn.IDConfigStaticLang 
		and typedoc.IDTemplate = template.IDTemplate 
		and template.IDConfigStaticLang = tpn.IDConfigStaticLang 
		and (tdn.EN like '%".$_REQUEST['namekey']."%' or tdn.VN like '%".$_REQUEST['namekey']."%' or tdn.KR like '%".$_REQUEST['namekey']."%' ) and typedoc.IDTemplate=".$_REQUEST['idtemplate']."  
		ORDER BY typedoc.IDTypeDoc asc";
		$mkqs=mysql_query($sql);
	}
	
	
	?>
	<link href="../css/style.css" rel="stylesheet" type="text/css" />
	<table cellpadding="5" cellspacing="0" class="rf_dt" >
                <tr  class="table_new">
                <td width="10%"><?php echo $l_no;?></td>
                <td width="35%"><?php echo $l_DocumentName;?></td>
                <td width="45%"><?php echo $l_title;?></td>
                <td width="10%"><?php echo $l_View;?></td>
                </tr>
                <?php 
                	if(count($mkqs)>0){
                		$vitri=0;
                		while ($row=mysql_fetch_array($mkqs)){
                			$vitri++;
                			?>
                			<tr>
			                <td><div align="center"><?php echo $vitri;?></div></td>
			                <td><?=$row[tpname]?></td>
			                <td><a href="newform.php?type=<?php echo $row[IDTypeDoc];?>&action=newform"><?=$row[tdname]?></a></td>
			                <td><div class="view_button"><a href="newform-<?php echo $row[IDTypeDoc];?>&newform"><img src="images/new.png" alt="" /></a></div></td>
			                </tr>
                			<?php   
                		}
                	}else{
                		echo "<tr><td colspan='4'>".$sql."</td></tr>";
                	}
                ?>
            </table>
	<?php 
}else{
	echo "ngu như bò";
}

 mysql_close($connection);
?>